package cn.kgc.javaweb.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.security.Key;

/**
 * @author: mosin
 * @version: v1.0  2022/9/4
 */
@WebServlet("/getCookie")
public class GetCookieServlet  extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        // 从请求对象中获取cookie
        Cookie[] cookies = req.getCookies();
        //遍历cookie
        if(cookies!=null){
            for (Cookie cookie : cookies) {
                //获取cookie的kay
                String name = cookie.getName();
                //获取cookie的value
                String value = cookie.getValue();
                System.out.println(name+  ":" + value);
            }
        }
    }
}
